Take Home Exercise 3

VAST Challenge 3

Huang Anni (Singapore Management University)
05-06-2022

The task

With reference to Challenge 3 of VAST Challenge 2022, you are required to reveal the economic of the city of Engagement, Ohio USA by using appropriate static and interactive statistical graphics methods

Introduction

This exercise requires us to apply the skills you had learned in Lesson 1 and Hands-on Exercise 1 to reveal the demographic of the city of Engagement, Ohio USA by using appropriate static statistical graphics methods. The data should be processed by using appropriate tidyverse family of packages and the statistical graphics must be prepared using ggplot2 and its extensions. image

y <- as.POSIXct(financial$timestamp, format="%Y-%m-%d %H:%M:%S")
financial$year <- format(y, format="%Y")
financial$month <- format(y, format="%m")

income <- financial %>%
  filter(category %in% c('Wage', 'RentAdjustment')) %>%
  group_by(year, month) %>%
  summarise(income = mean(amount))

outcome <- financial %>%
  filter(!category %in% c('Wage', 'RentAdjustment')) %>%
  group_by(year, month) %>%
  summarise(outcome = mean(abs(amount)))
total <- merge(income,outcome,by=c("year","month"))
total$date <- paste(total$year, total$month, sep='-')
total$coef <- total$outcome / total$income
unique(total$date)
 [1] "2022-03" "2022-04" "2022-05" "2022-06" "2022-07" "2022-08"
 [7] "2022-09" "2022-10" "2022-11" "2022-12" "2023-01" "2023-02"
[13] "2023-03" "2023-04" "2023-05"
library(rmarkdown)
paged_table(financial, options = list(rows.print = 15, cols.print = 5))
total$coef <- total$outcome/total$income
p1 <- ggplot(data=total) + aes(x=date, y=coef,group=1) +
  geom_line(color='black')+
  geom_point(color="black", fill="grey") +
  labs(y= 'Spend/Income', x= 'Date',
       title = "Fig 1.Residence's living status through time",
       subtitle = "Highest standards in 2022-04") +
  theme(axis.title.y= element_text(angle=90),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5),
        axis.ticks.x= element_blank(),
        panel.background= element_blank(), 
        axis.line= element_line(color= 'grey'),
        panel.grid.major.y = element_line(color = "grey",
                                  size = 0.75,
                                  linetype = 2))
girafe(
  ggobj = p1,
  width_svg = 6,
  height_svg = 6*0.618,
  options = list(
    opts_hover_inv(css = "stroke-width: 1;opacity:0.6;"),
    opts_hover(css = "stroke-width: 4; opacity: 1;"))
)
fig <- plot_ly(total, x = ~date, y = ~coef, type = 'scatter',mode = 'lines+markers')
fig <- fig %>% layout(title = 'Fig 1.Residence\'s living status through time',
                      xaxis = list(title = "Date"),
                      yaxis = list (title = "Spend/Income"))
fig
total$remain <- (total$income - total$outcome)
total$remain <- round(total$remain, 1)
ggplot(data=total, aes(x=date, y=remain)) +
  geom_bar(stat = "identity", width = 0.5, fill="steelblue") +
  labs(y= 'Fig2. Total Deposit\n(Dollar)', x= 'Date',
       title = "Trend of Living Standards",
       subtitle = "Highest remaining in 2022-03") +
  geom_text(aes(label = remain), vjust = -1.5, colour = "white") +
  theme(axis.title.y= element_text(angle=90),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5),
        axis.ticks.x= element_blank(),
        panel.background= element_blank(), 
        axis.line= element_line(color= 'grey'), 
        panel.grid.major.y = element_line(color = "grey",size = 0.5,linetype = 2))

total$remain <- (total$income - total$outcome)
total$remain <- round(total$remain, 1)
ggplot(data=total, aes(x=date, y=remain)) +
  geom_bar(stat = "identity", width = 0.5, fill="steelblue") +
  coord_cartesian(ylim = c(0, 160)) + 
  labs(y= 'Total Deposit', x= 'Date',
       title = "Fig2. Trend of Living Standards",
       subtitle = "Highest remaining in 2022-03") +
  geom_text(aes(label = remain), vjust = -1, colour = "black") +
  theme(axis.title.y= element_text(angle=90),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5),
        axis.ticks.x= element_blank(),
        panel.background= element_blank(), 
        axis.line= element_line(color= 'grey'), 
        panel.grid.major.y = element_line(color = "grey",size = 0.5,linetype = 2))

fig <- plot_ly(total, x = ~income, type = "histogram")

fig